<template>
  <d2-container>
    <template slot="header">商户信息</template>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        label="序号"
        type="index"
        width="60">
      </el-table-column>
      <el-table-column
        prop="admin"
        label="邀请人"
        width="120">
      </el-table-column>
      <el-table-column
        prop="user"
        label="商户名"
        width="120">
      </el-table-column>
      <el-table-column
        prop="userkey"
        label="邀请码"
        width="120">
      </el-table-column>
      <el-table-column
        prop="phone"
        label="手机号"
        width="120">
      </el-table-column>
      <el-table-column
        prop="qq"
        label="QQ"
        width="120">
      </el-table-column>
      <el-table-column
        label="商户状态"
        width="120">
        <template slot-scope="scope">
          <span @click="jihuo(scope.row)" style="cursor: pointer;color:red;" v-show="scope.row.status == 1">已激活</span>
          <span style="cursor: pointer;" v-show="scope.row.status != 1">未激活</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="com_money"
        label="佣金余额"
        width="120">
      </el-table-column>
      <el-table-column
        prop="cum_money"
        label="累计消费佣金"
        width="120">
      </el-table-column>
      <el-table-column
        prop="money"
        label="余额"
        width="120">
      </el-table-column>
      <el-table-column
        prop="create_time"
        label="入驻时间"
        width="180">
      </el-table-column>
    </el-table>
    <el-pagination
      v-if="total >= 20"
      @current-change="handleCurrentChange"
      :current-page.sync="page"
      :page-size="20"
      layout="total, prev, pager, next"
      :total="total"
      style="text-align:right;margin:10px 0;">
    </el-pagination>
  </d2-container>
</template>

<script>
import { cooperationlist } from '@api/sys.login'
export default {
  name: 'merchants',
  data(){
    return{
      tableData:[],
      page:1,
      total:0,
    }
  },
  mounted(){
    this.getUserList()
  },
  methods:{
    jihuo(row){
      console.log(row);
    },
    handleCurrentChange(val) {
      this.page = val
      this.getUserList()
    },
    // 获取列表数据
    getUserList(){
      cooperationlist({
        page:this.page,
        pageSize:20
      })
        .then((res) => {
          console.log('商户列表',res)
          let temp = res.data
          temp.forEach(element => {
            element.create_time = this.getLocalTime(element.create_time)
          });
          this.tableData = temp
          this.total = res.count
        })
        .catch(() =>{
          this.tableData = []
          this.total = 0
        })
    },
    getLocalTime(nS) {
      return new Date(parseInt(nS) * 1000).toLocaleString().replace(/:\d{1,2}$/,' ');
    }
  }
}
</script>
